package cmd

import (
	"fmt"

	"github.com/spf13/cobra"
)

var ClearCmd = &cobra.Command{
	Use:   "clear",
	Short: "自动清理当前无用镜像",
	RunE: func(cmd *cobra.Command, args []string) error {
		return pruneImages()
	},
}

var DeleteCmd = &cobra.Command{
	Use:   "delete",
	Short: "按条件删除镜像",
	RunE: func(cmd *cobra.Command, args []string) error {
		nameFilter, _ := cmd.Flags().GetString("name")
		idFilter, _ := cmd.Flags().GetString("id")
		regexFilter, _ := cmd.Flags().GetString("regex")
		force, _ := cmd.Flags().GetBool("force")

		return deleteImages(nameFilter, idFilter, regexFilter, force)
	},
}

func init() {
	DeleteCmd.Flags().StringP("name", "n", "", "按镜像名称过滤")
	DeleteCmd.Flags().StringP("id", "i", "", "按镜像ID过滤")
	DeleteCmd.Flags().StringP("regex", "r", "", "按正则表达式过滤")
	DeleteCmd.Flags().BoolP("force", "f", false, "强制删除")
}

// 模拟实现
func pruneImages() error {
	fmt.Println("清理无用镜像功能待实现")
	return nil
}

func deleteImages(name, id, regex string, force bool) error {
	fmt.Printf("删除镜像功能待实现: name=%s, id=%s, regex=%s, force=%v\n", name, id, regex, force)
	return nil
}
